package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.RequestAndResultCode;
import com.bjesc_b2c.app.appraiset.adapter.CarDetailsImageAdapter;
import com.bjesc_b2c.app.appraiset.base.BaseActivity;
import com.bjesc_b2c.app.appraiset.http.IApiActivityRequest;
import com.bjesc_b2c.app.appraiset.mvp.presenter.impl.CarDetailsPresenter;
import com.bjesc_b2c.app.appraiset.mvp.presenter.impl.CarDetailsPresenterImpl;
import com.bjesc_b2c.app.appraiset.mvp.view.CarDateilsView;
import com.bjesc_b2c.app.appraiset.utils.BitmapUtil;
import com.bjesc_b2c.app.appraiset.utils.CustomSharedPreferences;
import com.bjesc_b2c.app.appraiset.widget.popupwindow.ShareCarPop;
import com.bumptech.glide.Glide;
import com.orhanobut.logger.Logger;
import com.rxretrofit_build.util.MapUtil;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.loader.ImageLoaderInterface;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import app.pinggushi.bjesc.com.baserecyclerview.adapter.CommonAdapter;
import butterknife.Bind;
import butterknife.OnClick;
import cn.jiguang.share.android.api.JShareInterface;
import cn.jiguang.share.android.api.PlatActionListener;
import cn.jiguang.share.android.api.Platform;
import cn.jiguang.share.android.api.ShareParams;
import master_bean.CarDetailsBean;
import rxretrofit_base.model.KeyBean;
import rxretrofit_base.model.ShowType;
import rxretrofit_base.model.TokenBean;
import rxretrofit_base.net.BaseSubscriber;
import rxretrofit_base.net.RxRequest;

/**
 * Created by yidong on 2017/8/4.
 */

public class CarDetailsActivity extends BaseActivity implements CarDateilsView, CommonAdapter.OnItemClickListener, ShareCarPop.shareType {
    private CarDetailsPresenter presenter;
    @Bind(R.id.banner)
    Banner banner;
    @Bind(R.id.tv_info_title)
    TextView titleTv;
    @Bind(R.id.tv_info_status)
    TextView statusTv;
    @Bind(R.id.tv_info_origin)
    TextView originTv;
    @Bind(R.id.tv_info_price)
    TextView priceTv;
    @Bind(R.id.tv_car_maintain)
    TextView carMaintainTv;
    @Bind(R.id.tv_info_publish_time)
    TextView publishTimeTv;
    @Bind(R.id.tv_car_maintain_phone)
    TextView carMainPhoneTv;
    @Bind(R.id.tv_car_dealers_name)
    TextView dealersNameTv;
    @Bind(R.id.tv_dealer_contact_person)
    TextView dealersContactTv;
    @Bind(R.id.tv_car_dealers_phone)
    TextView dealersPhoneTv;
    @Bind(R.id.tv_dealer_address)
    TextView dealersAddressTv;
    @Bind(R.id.tv_car_vin)
    TextView carVinTv;
    @Bind(R.id.tv_on_the_card_time)
    TextView carTimeTv;
    @Bind(R.id.tv_car_color)
    TextView carColorTv;
    @Bind(R.id.tv_displacement)
    TextView carDisplacement;
    @Bind(R.id.tv_use_nature)
    TextView carUseNature;
    @Bind(R.id.tv_emission)
    TextView caremussinTv;
    @Bind(R.id.tv_mileage)
    TextView carMileageTv;
    @Bind(R.id.tv_mortgage)
    TextView carMortgageTv;
    @Bind(R.id.tv_car300)
    TextView car300Tv;
    @Bind(R.id.tv_reserve_price)
    TextView carReservePriceTv;
    @Bind(R.id.tv_factory_time)
    TextView carFactoryTv;
    @Bind(R.id.tv_transfer)
    TextView cartransferTv;
    @Bind(R.id.tv_maintenance)
    TextView carMaintenanceTv;
    @Bind(R.id.tv_driving_license)
    TextView drivingTv;
    @Bind(R.id.tv_registration)
    TextView registrationTv;
    @Bind(R.id.tv_key_num)
    TextView keyNumTv;
    @Bind(R.id.tv_after_warranty)
    TextView afterTv;
    @Bind(R.id.tv_warranty_expire)
    TextView warrantyTv;
    @Bind(R.id.tv_commercial_insurance)
    TextView commercialTv;
    @Bind(R.id.commercial_expire)
    TextView commercial_expire;
    @Bind(R.id.tv_seat_function)
    TextView seatFunctiontV;
    @Bind(R.id.tv_airbag)
    TextView airbagTv;
    @Bind(R.id.tv_gearbox)
    TextView gearboxTv;
    private String carID;
    @Bind(R.id.recycleView)
    RecyclerView recyclerView;
    @Bind(R.id.tv_title)
    TextView titleTV;

    private CarDetailsImageAdapter mAapter;
    private Intent imageIntent;
    private  String imageUrl;
    private String shareTitle;
    private String shareText;
    private String shareUrl;
    private boolean isShare;
    private boolean isRefresh;
    private ArrayList<String> imageUrls = new ArrayList<>();

    @Override
    protected int getLayout() {
        return R.layout.fragment_car_details;
    }

    @Override
    protected void initEventAndData() {
        imageIntent = new Intent(this, CarImageActivity.class);
        titleTV.setText("车辆详情");
        carID = CustomSharedPreferences.getString(this, KeyBean.CARID.valueOf(), KeyBean.FILE_NAME.valueOf());
        String userID = CustomSharedPreferences.getString(this, KeyBean.UID.valueOf(), KeyBean.FILE_NAME.valueOf());
        shareUrl = "http://m.bjesc.com/dealerDetail/" + carID + ".html?aff=" + userID;
        GridLayoutManager manager = new GridLayoutManager(this, 2);
        recyclerView.setLayoutManager(manager);
    }

    @Override
    protected void createPresenter() {
        presenter = new CarDetailsPresenterImpl(this);
        presenter.getCarDetails(this);
    }

    @Override
    public void getCarDateils(CarDetailsBean carBean) {
        setInfo(carBean);
        List<String> imageTitle = new ArrayList<>();
        for (int i = 0; i < carBean.getBannerImg().size(); i++) {
            String image = carBean.getBannerImg().get(i);
            if (image.contains("/98/")) {
                imageUrl = carBean.getBannerImg().get(i);
                DownThread mThread = new DownThread();
                mThread.start();
            }
            Logger.d(image);
            imageTitle.add(carID);
            imageUrls.add(image);
        }
        //设置banner样式（显示圆形指示器和标题）
        banner.setBannerStyle(BannerConfig.NUM_INDICATOR_TITLE);
        //设置banner动画效果（正方体旋转式）
        //banner.setBannerAnimation(Transformer.CubeOut);
        //设置标题集合（当banner样式有显示title时）
        banner.setBannerTitles(imageTitle);
        //设置自动轮播，默认为true
        banner.isAutoPlay(true);
        //设置轮播时间
        banner.setDelayTime(4000);
        //设置指示器位置：左侧显示（当banner模式中有指示器时）
        //banner.setIndicatorGravity(BannerConfig.RIGHT);
        //新版的banner的使用----偷下懒的使用方法
        banner.setImages(imageUrls).setImageLoader(new ImageLoaderInterface() {
            @Override
            public void displayImage(Context context, Object path, View imageView) {
                Glide.with(context)
                        .load(path)
                        .placeholder(R.mipmap.ic_placeholder_small)
                        .error(R.mipmap.ic_loadding_error_small) // will be displayed if the image canot be loaded
                        .into((ImageView) imageView);
            }

            @Override
            public View createImageView(Context context) {
                return null;
            }
        }).start();
        if (mAapter == null) {
            mAapter = new CarDetailsImageAdapter(this, R.layout.layout_item_car_details, carBean.getImgs());
            mAapter.setOnItemClickListener(this);
            recyclerView.setAdapter(mAapter);
        }
    }

    @OnClick({R.id.iv_maintain_msg, R.id.iv_maintain_phone, R.id.iv_dealers_phone, R.id.iv_dealers_msg, R.id.iv_return, R.id.share_iv,R.id.tv_change_dealer})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_return:
                if (isRefresh) {
                    setResult(20);
                }
                finish();
                break;
            case R.id.iv_maintain_phone:
                call(carMainPhoneTv.getText().toString());
                break;
            case R.id.iv_maintain_msg:
                sendto(carMainPhoneTv.getText().toString());
                break;
            case R.id.iv_dealers_phone:
                call(dealersPhoneTv.getText().toString());
                break;
            case R.id.iv_dealers_msg:
                sendto(dealersPhoneTv.getText().toString());
                break;
            case R.id.share_iv:
                if (isShare) {
                    ShareCarPop pop = new ShareCarPop(this, this);
                    pop.setTitles(imageUrl, shareTitle);
                    pop.showAtLocation(this.findViewById(R.id.lin_root), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                } else {
                    showToast("该车源未上架不能分享");
                }
                break;
            case R.id.tv_change_dealer:
                Intent intent = new Intent(mContext, MarketActivity.class);
                intent.putExtra("TYPE", 4);//修改車行
                intent.putExtra("CAR_ID", carID);
                startIntent(intent, RequestAndResultCode.BasicActivity_To_CarFromActivity);
                break;
        }
    }

    @Override
    public void shareType(String typeId, String title) {
        ClipboardManager cmb = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData myClip;
        myClip = ClipData.newPlainText("text", shareText);
        cmb.setPrimaryClip(myClip);
        showToast("已复制在剪贴板");
        if (typeId.equals(ShareCarPop.MORE_IMAGE)) {
            Intent intent = new Intent(CarDetailsActivity.this, ImageSelectActivity.class);
            intent.putExtra("shareUrl", shareUrl);
            intent.putExtra("shareText", shareText);
            intent.putStringArrayListExtra("imageUrls", imageUrls);
            startActivity(intent);
        } else if(typeId.equals(ShareCarPop.QQ)||typeId.equals(ShareCarPop.QZONE)){
            ShareParams shareParams = new ShareParams();
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            Logger.d("url===" + shareUrl);
            shareParams.setText(title);
            shareParams.setTitle("【博精二手车】");
            shareParams.setUrl(shareUrl);
            shareParams.setImageUrl(imageUrl);
            JShareInterface.share(typeId, shareParams, mShareListener);
        }else {
            ShareParams shareParams = new ShareParams();
            shareParams.setShareType(Platform.SHARE_WEBPAGE);
            Logger.d("url===" + shareUrl);
            shareParams.setTitle("【博精二手车】"+title);
            shareParams.setUrl(shareUrl);
            shareParams.setImageData(bitmap1);
            JShareInterface.share(typeId, shareParams, mShareListener);
        }
    }

    @Override
    public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
        imageIntent.putExtra("checkedId", position);
        startIntent(imageIntent, false);
    }

    @Override
    public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
        return false;
    }

    /**
     * 调用拨号功能
     *
     * @param phone 电话号码
     */

    private void call(String phone) {
        Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    private void sendto(String phone) {
        Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phone));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }

    private void setInfo(CarDetailsBean carBean) {
        if (!TextUtils.isEmpty(carBean.getCarInfo().getTitle())) {
            titleTv.setText(carBean.getCarInfo().getTitle());
        }
        shareTitle = carBean.getCarInfo().getTitle() + "  " + carBean.getCarInfo().getPrice() + "万  " +
                carBean.getCarDetailsInfo().getBasicInformation().getTravel_mileage() + "万公里";
        shareText = "【车辆型号】" + carBean.getCarInfo().getTitle() + "\n" +
                "【行驶里程】" + carBean.getCarDetailsInfo().getBasicInformation().getTravel_mileage() + "万公里" + "\n" +
                "【车辆价格】" + carBean.getCarInfo().getPrice() + "万";
        if (!TextUtils.isEmpty(carBean.getCarInfo().getStatus())) {
            String status = carBean.getCarInfo().getStatus();
            if (status.equals("TRACK")) {
                status = "线索";
            }
            if (status.equals("EXAMINING")) {
                status = "总部待审";
            }
            if (status.equals("KENTNOPASS")) {
                status = "总部不通过";
            }
            if (status.equals("PUBLISHPASS")) {
                status = "上架";
                isShare = true;
            }
            if (status.equals("COMMUNICATED")) {
                status = "内部交流";
            }
            if (status.equals("ENDDOWN")) {
                status = "下架";
            }
            statusTv.setText("车源状态：" + status);
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOrigin())) {
            originTv.setText(carBean.getCarInfo().getOrigin());
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getPrice())) {
            priceTv.setText(carBean.getCarInfo().getPrice() + "万");
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getPublish_time())) {
            publishTimeTv.setText(carBean.getCarInfo().getPublish_time() + "(" + carBean.getCarInfo().getPublish_day() + "天)");
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getDealer_address())) {
            dealersAddressTv.setText(carBean.getCarInfo().getOriginInfo().getDealer_address());
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getDealer_name())) {
            dealersNameTv.setText(carBean.getCarInfo().getOriginInfo().getDealer_name());
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getDealer_boss())) {
            dealersContactTv.setText(carBean.getCarInfo().getOriginInfo().getDealer_boss());
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getDealer_phone())) {
            dealersPhoneTv.setText(carBean.getCarInfo().getOriginInfo().getDealer_phone());
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getExamines_name())) {
            carMaintainTv.setText(carBean.getCarInfo().getOriginInfo().getExamines_name());
        }
//        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getExamines_phone())) {
//            carMainPhoneTv.setText(carBean.getCarInfo().getOriginInfo().getExamines_phone());
//            shareText +=shareText+"/n【联系电话】"+carBean.getCarInfo().getOriginInfo().getExamines_phone();
//        }

    /* ##############################################基本信息############################################## **/
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getVin())) {
            carVinTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getVin());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getCar_color())) {
            carColorTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getCar_color());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getLicense_time())) {
            carTimeTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getLicense_time());
            shareText += "\n【上牌时间】" + carBean.getCarDetailsInfo().getBasicInformation().getLicense_time();
        }
        if (!TextUtils.isEmpty(carBean.getCarInfo().getOriginInfo().getExamines_phone())) {
            carMainPhoneTv.setText(carBean.getCarInfo().getOriginInfo().getExamines_phone());
            shareText += "\n【联系电话】4006-122-111";
        }
        shareText += "\n【车辆详情】" + shareUrl;
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getDisplacement())) {
            carDisplacement.setText(carBean.getCarDetailsInfo().getBasicInformation().getDisplacement() + "L");
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getEmission_standard())) {
            String carEmu = carBean.getCarDetailsInfo().getBasicInformation().getEmission_standard();
            if (carEmu.equals("1")) {
                caremussinTv.setText("国二");
            }
            if (carEmu.equals("2")) {
                caremussinTv.setText("国三");
            }
            if (carEmu.equals("3")) {
                caremussinTv.setText("国四");
            }
            if (carEmu.equals("4")) {
                caremussinTv.setText("国五");
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getTravel_mileage())) {
            carMileageTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getTravel_mileage() + "万公里");
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getMortgage())) {
            String mortg = carBean.getCarDetailsInfo().getBasicInformation().getMortgage();
            switch (Integer.valueOf(mortg)) {
                case 1:
                    carMortgageTv.setText("无按揭");
                    break;
                case 2:
                    carMortgageTv.setText("已还清，但未拿证");
                    break;
                case 3:
                    carMortgageTv.setText("没还清，卖方还");
                    break;
                case 4:
                    carMortgageTv.setText("没还清 买方还");
                    break;
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getProduction_time())) {
            carFactoryTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getProduction_time());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getTransfer_num())) {
            cartransferTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getTransfer_num());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getMaintain_place())) {
            String maintainPlace = carBean.getCarDetailsInfo().getBasicInformation().getMaintain_place();
            if (maintainPlace.equals("1")) {
                carMaintenanceTv.setText("4S");
            } else {
                carMaintenanceTv.setText("非4S");
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getLow_price())) {
            carReservePriceTv.setText(carBean.getCarDetailsInfo().getBasicInformation().getLow_price() + "万");
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getFair_price())) {
            car300Tv.setText(carBean.getCarDetailsInfo().getBasicInformation().getFair_price() + "万");
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getBasicInformation().getUse_property())) {
            String usePro = carBean.getCarDetailsInfo().getBasicInformation().getUse_property();
            if (usePro.equals("0")) {
                carUseNature.setText("不详");
            }
            if (usePro.equals("1")) {
                carUseNature.setText("非营运");
            }
            if (usePro.equals("2")) {
                carUseNature.setText("运营转非营运");
            }
            if (usePro.equals("3")) {
                carUseNature.setText("营运");
            }
        }
    /* ##############################################手续信息############################################## **/

        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getIs_vehicle_passport())) {
            String driving = carBean.getCarDetailsInfo().getProceduresInformation().getIs_vehicle_passport();
            if (driving.equals("0")) {
                drivingTv.setText("不详");
            }
            if (driving.equals("1")) {
                drivingTv.setText("有");
            }
            if (driving.equals("2")) {
                drivingTv.setText("无");
            }
        }

        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getRegistration())) {
            String regis = carBean.getCarDetailsInfo().getProceduresInformation().getRegistration();
            if (regis.equals("1")) {
                registrationTv.setText("有");
            }
            if (regis.equals("2")) {
                registrationTv.setText("无");
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getKey_num())) {
            keyNumTv.setText(carBean.getCarDetailsInfo().getProceduresInformation().getKey_num());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getAfter_warranty())) {
            String warranty = carBean.getCarDetailsInfo().getProceduresInformation().getAfter_warranty();
            if (warranty.equals("0")) {
                afterTv.setText("不详");
            }
            if (warranty.equals("1")) {
                afterTv.setText("过保");
            }
            if (warranty.equals("2")) {
                afterTv.setText("未过保");
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getCommercial_insurance_expire())) {
            commercial_expire.setText(carBean.getCarDetailsInfo().getProceduresInformation().getCommercial_insurance_expire());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getCompulsory_insurance_expire())) {
            warrantyTv.setText(carBean.getCarDetailsInfo().getProceduresInformation().getCompulsory_insurance_expire());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getProceduresInformation().getCommercial_insurance())) {
            String commercial = carBean.getCarDetailsInfo().getProceduresInformation().getCommercial_insurance();
            if (commercial.equals("0")) {
                commercialTv.setText("不详");
            }
            if (commercial.equals("1")) {
                commercialTv.setText("有");
            }
            if (commercial.equals("2")) {
                commercialTv.setText("无");
            }
        }

        /* ##############################################配置信息############################################## **/

        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getConfigurationInformation().getGasbug())) {
            airbagTv.setText(carBean.getCarDetailsInfo().getConfigurationInformation().getGasbug());
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getConfigurationInformation().getGearbox())) {
            String gearbox = carBean.getCarDetailsInfo().getConfigurationInformation().getGearbox();
            if (gearbox.equals("1")) {
                gearboxTv.setText("自动");
            }
            if (gearbox.equals("2")) {
                gearboxTv.setText("手动");
            }
        }
        if (!TextUtils.isEmpty(carBean.getCarDetailsInfo().getConfigurationInformation().getSeat_function())) {
            String function = carBean.getCarDetailsInfo().getConfigurationInformation().getSeat_function();
            if (function.equals("0")) {
                seatFunctiontV.setText("无");
            }
            if (function.equals("1")) {
                seatFunctiontV.setText("电加热");
            }
            if (function.equals("2")) {
                seatFunctiontV.setText("通风");
            }
            if (function.equals("3")) {
                seatFunctiontV.setText("按摩");
            }

        }
    }


    private PlatActionListener mShareListener = new PlatActionListener() {
        @Override
        public void onComplete(Platform platform, int action, HashMap<String, Object> data) {
            shareSuc(carID);
            if (handler != null) {
                Message message = handler.obtainMessage();
                message.obj = "分享成功";
                handler.sendMessage(message);
            }
        }

        @Override
        public void onError(Platform platform, int action, int errorCode, Throwable error) {

            if (handler != null) {
                Message message = handler.obtainMessage();
                if (errorCode == 41011) {
                    message.obj = "分享失败:标题描述文字过长请重新编辑";
                } else {
                    message.obj = "分享失败:" + error.getMessage();
                }
                Logger.d("SHAREerror:" + errorCode + ",msg:" + error);
                handler.sendMessage(message);
            }
        }

        @Override
        public void onCancel(Platform platform, int action) {
            if (handler != null) {
                Message message = handler.obtainMessage();
                message.obj = "分享取消";
                handler.sendMessage(message);
            }
        }
    };
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String toastMsg = (String) msg.obj;
            showToast(toastMsg);
            cancelLoading();
        }
    };
    private void shareSuc(String carID){
        HashMap<String, Object> build = new MapUtil()
                .put("car_id",carID)
                .build();
        RxRequest.request(ShowType.DISMISS, RxRequest.getClient(mContext, build).create(IApiActivityRequest.class).shareCode(),
                new BaseSubscriber<TokenBean>(mContext) {
                    @Override
                    public void onSuccess(TokenBean o) {

                    }
                    @Override
                    public void onFailure(Throwable e) {

                    }
                });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case 2:
                isRefresh = true;
                if (presenter != null) {
                    presenter.getCarDetails(this);
                }
                break;
        }
    }

    @Override
    public void onBackPressed() {
        if (isRefresh) {
            setResult(20);
        }
        finish();
    }

    Bitmap bitmap1;
    String imageName;
    class DownThread extends Thread {
        @Override
        public void run() {
            super.run();
            Logger.d("imageUrl===="+imageUrl);
            try {
                byte[] data1 = BitmapUtil.getImage(imageUrl);
                Logger.d("imageUrl===="+imageUrl);
                    if (data1 != null) {
                        bitmap1 = BitmapFactory.decodeByteArray(data1, 0, data1.length);// bitmap
                        Logger.d("bitmap1===="+bitmap1);
                    }
                }catch(Exception e){
                Logger.d(e.getMessage());
                }

        }
    }
}
